package com.stary.code.springboot.config;

import java.io.File;

import org.apache.commons.lang.StringUtils;

import com.stary.code.springboot.Constants;

/**
 * <p>maven 配置类</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2018-6-29
 */
public class MavenConfig {

	/**
	 * maven工程 src/main/java 目录
	 */
	public final String MAVEN_MAIN_JAVA = File.separator + "src" + File.separator + "main" + File.separator + "java";
	/**
	 * maven工程 /src/main/resources 目录
	 */
	public final String MAVEN_MAIN_RESOURCES = File.separator + "src" + File.separator + "main" + File.separator + "resources";
	/**
	 * maven工程 /src/test/java 目录
	 */
	public final String MAVEN_TEST_JAVA = File.separator + "src" + File.separator + "test" + File.separator + "java";
	/**
	 * maven工程 pom.xml文件路径
	 */
	public final String MAVEN_POM_XML = File.separator;
	/**
	 * maven工程 webapp目录
	 */
	public final String MAVEN_WEBAPP = File.separator + "src" + File.separator + "main" + File.separator + "webapp";
	/**
	 * POM文件是遵从4.0.0版本的项目描述符
	 */
	private final String modelVersion = "4.0.0";
	/**
	 * 项目的唯一的标识符，对应项目的名称，就是项目根目录的名称
	 */
	private String artifactId = "demo";
	/**
	 * 项目组织唯一的标识符，对应JAVA的包的结构，是main目录里java的目录结构
	 */
	private String groupId = "com.stary";
	/**
	 * 打包版本号，默认 0.0.1-SNAPSHOT
	 */
	private String version = "0.0.1-SNAPSHOT";
	/**
	 *  打包方式，war或jar，默认war
	 */
	private String packaging = Constants.WAR;	
	/**
	 * 项目名称
	 */
	private String name;
	/**
	 * 项目描述简介
	 */
	private String description = "Demo project for Spring Boot";

	public String getArtifactId() {
		return artifactId;
	}
	public MavenConfig setArtifactId(String artifactId) {
		this.artifactId = artifactId;
		return this;
	}
	public String getGroupId() {
		return groupId;
	}
	public MavenConfig setGroupId(String groupId) {
		this.groupId = groupId;
		return this;
	}
	public String getVersion() {
		return version;
	}
	public MavenConfig setVersion(String version) {
		this.version = version;
		return this;
	}
	public String getPackaging() {
		return packaging;
	}
	public MavenConfig setPackaging(String packaging) {
		this.packaging = packaging;
		return this;
	}
	public String getName() {
		if (StringUtils.isEmpty(name)) {
			name = getArtifactId();
		}
		return name;
	}
	public MavenConfig setName(String name) {
		this.name = name;
		return this;
	}
	public String getDescription() {
		return description;
	}
	public MavenConfig setDescription(String description) {
		this.description = description;
		return this;
	}
	public String getModelVersion() {
		return modelVersion;
	}

	/**
	 * 获取 artifactId/src/main/java/groupId/artifactId目录
	 * @return
	 */
	public String getMainJavaDir() {
		StringBuilder dir = new StringBuilder(artifactId);
		dir.append(MAVEN_MAIN_JAVA)
		.append(File.separator)
		.append(groupId.replace(Constants.POINT, File.separator))
		.append(File.separator)
		.append(artifactId);
		return dir.toString();
	}
	/**
	 * 获取 artifactId/src/main/java/artifactId/目录
	 * @return
	 */
	public String getMainDir() {
		StringBuilder dir = new StringBuilder(artifactId);
		dir.append(MAVEN_MAIN_JAVA).append(File.separator);
		return dir.toString();
	}
	/**
	 * 获取 artifactId/src/main/resources目录
	 * @return
	 */
	public String getMainResourcesDir() {		
		return artifactId + MAVEN_MAIN_RESOURCES;
	}
	/**
	 * 获取 artifactId/src/test/java/groupId/artifactId目录
	 * @return
	 */
	public String getTestJavasDir() {	
		StringBuilder dir = new StringBuilder(artifactId);
		dir.append(MAVEN_TEST_JAVA)
		.append(File.separator)
		.append(groupId.replace(Constants.POINT, File.separator))
		.append(File.separator)
		.append(artifactId);
		return dir.toString();
	}
	/**
	 * 获取 artifactId/src/main/webapp目录 jsp
	 * @return
	 */
	public String getWebappDir() {		
		return artifactId + MAVEN_WEBAPP;
	}
	
}
